package com.ruoyi.wx.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.wx.pojo.vo.CommonMsgVo;
import com.ruoyi.wx.pojo.vo.MassMess;
import com.ruoyi.wx.pojo.vo.SendTemplateVo;
import com.ruoyi.wx.service.WxMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/wx/message")
public class WxMessageController {

    @Autowired
    private WxMessageService wxMessageService;

    @GetMapping("/id")
    public AjaxResult getTemplateId() {
        wxMessageService.getTemplateId();
        return AjaxResult.success();
    }

    @PostMapping("/sendmsg")
    public AjaxResult sendMsg(@RequestBody MassMess massMess) {
        if (!wxMessageService.massSendTemplateMessage(massMess)) return AjaxResult.error("错误");
        return AjaxResult.success();
    }

    @PostMapping("send/commen/message")
    public AjaxResult sendCommonMessage(@RequestBody CommonMsgVo commonMsgVo) {
        wxMessageService.sendCommonMessage(commonMsgVo);
        return AjaxResult.success();
    }

    @PostMapping("/sendtemplatemsg")
    public AjaxResult sendTemplateMsg(@RequestBody SendTemplateVo sendTemplateVo) {
        if (!wxMessageService.sendTemplateMessage(sendTemplateVo)) return AjaxResult.error("错误");
        return AjaxResult.success();
    }

    /**
     * 提醒商家发货
     */
    @GetMapping("/tip/business")
    public AjaxResult tipBusiness(String memberId, String content) {
        wxMessageService.tipBusiness(memberId, content);
        return AjaxResult.success();
    }

    /**
     * 寄样品让那些商家
     */
    @GetMapping("/a/b")
    public AjaxResult a(int id, String userId, String content, String title, String status) {
        boolean c = wxMessageService.c(id, userId, content, title, status);
        if (c) return AjaxResult.success();
        else return AjaxResult.error("发送失败");
    }
}
